#include <AppStream.hpp>
#include "Max.h"
#include "stdmat.h"
#include "imtl.h"

#ifndef _CLASSMAXEXPORTERMAXSTREAM_
#define _CLASSMAXEXPORTERMAXSTREAM_

namespace MaxExporter {

class MaxStream : public Modeling::AppStream
{
public:
	virtual ~MaxStream();
	MaxStream(INode* iroot);

	size_t write(Modeling::Scene* scene);
	size_t write(Modeling::Mesh* mesh);

	size_t read(Modeling::Scene* scene);
	size_t read(Modeling::Mesh* mesh);

private:
	FILE* file;
	INode* iroot;
	Modeling::Scene* scene;
	Modeling::Root* root;

	Interval animInterval;
	TimeValue framesInterval;

	std::vector< Modeling::Material* > tempMaterial;

	size_t readAnimation(Modeling::Animation* animation);
	size_t readNode(INode* inode);
	size_t readMaterial(INode* node);
	void castMaterial(Mtl* mtl);
	void addMaterial(Mtl* mtl);
	size_t readMatrices(INode* inode, Modeling::Node* node);
	size_t readVertices(Mesh& iMesh, Modeling::Mesh* mesh);
	size_t readFaces(Mesh& iMesh, Modeling::Mesh* mesh);
	size_t readTexCoords(Mesh& imesh,  Modeling::Mesh* mesh);
	void generateNormals(Modeling::Mesh* mesh, std::vector<DWORD>& smoothGroup);
};

}// namespace MaxExporter

#endif
